package com.heatingcharge.controller.charge;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.heatingcharge.common.util.R;
import com.heatingcharge.common.util.WordUtils;
import com.heatingcharge.dto.ArrearsDTO;
import com.heatingcharge.dto.UserArrearsDTO;
import com.heatingcharge.param.SearchParam;
import com.heatingcharge.service.charge.IClearOffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 清欠控制器
 * User: Devin
 * Date: 2019-12-23
 * Time: 16:30
 */
@RestController
@RequestMapping("/clearOff")
public class ClearOffController {

    @Autowired
    IClearOffService clearOffService;

    @GetMapping("/")
    public String index(){
        return "清欠中心";
    }
    /**
     * 获取所有小区的清欠统计信息
     * @return
     */
    @GetMapping("/all")
    public R getAllZonesStatistics(){

        return R.ok();
    }

    /**
     * 下载催缴单
     * @return
     */
    @GetMapping("/bill")
    public void downLoadBill(SearchParam searchParam,HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> arreasMap = clearOffService.getArreasMap(searchParam);
        try {
            WordUtils.exportMillCertificateWord(request, response, arreasMap, "催缴通知单", "bill.ftl");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * 获取欠费明细表 以小区为单位或者以楼栋为单位
     * @param searchParam
     * @return
     */
    @GetMapping("/arrearsReport")
    public R getArrearsReport(SearchParam searchParam){
        if(ObjectUtil.isNotEmpty(searchParam.getZoneId())&&searchParam.getZoneId()>0){
            return R.ok(clearOffService.getBuildingsArreas(searchParam));
        }
        else if(ObjectUtil.isNotEmpty(searchParam.getBuildId())&&searchParam.getBuildId()>0){
            return R.ok(clearOffService.getUnitssArreas(searchParam));
        }else {
            return R.ok(clearOffService.getZonesArreas(searchParam));
        }
    }
}
